package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;


public class Library {
    private String name;
    private List<Book> books;

    public Library(String name) {
        this.name = name;
        this.books = new ArrayList<Book>();
    }

    public String getName() {
        return name;
    }

    public List<Book> getBooks() {
        return books;
    }

    public void addBook(Book book) {
        books.add(book);
    }

    public void displayBooks() {
        System.out.println("List of all Books available:");
        for (Book book : books) {
            System.out.println(book);
        }
    }

    public boolean checkOutBook(int bookId) {
        Book book = getBook(bookId);
        if(book == null){
            return false;
        }
        return book.checkOut();
    }

    private Book getBook(int bookId) {
        for(Book book : books){
            if(book.getId() == bookId)
                return book;
        }
        return null;
    }

    public boolean returnBook(int bookId) {
        Book book = getBook(bookId);
        if(book == null){
            return false;
        }
        return book.returnItself();
    }
}

